<template>
	<view class="account">
		<view class="box" v-for="item in list" :key="item._id" @click="todetail(item._id)">
			<view class="image">
				<image src="../../static/images/tabbar/zhangben.png" mode=""></image>
			</view>
			<view class="text">
				<view class="name">
					{{item.name}}
				</view>
				<view class="people">
					{{item.userIds.length}}人
				</view>
			</view>
		</view>
		<view @click="submit" class="submit">新增账本</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			submit() {
				uni.navigateTo({
					url: '/pages/myaccount/addAccount'
				})
			},
			init() {
				let data = {
					id: uni.getStorageSync('userInfo')._id
				}
				this.$cloudApi.call({
					name: 'getAccount',
					data,
					success: res => {
						// uni.reLaunch({
						// 	url: '/pages/index/index'
						// })
						console.log(res);
						this.list = res.data
					}
				});
			},
			todetail(id) {
				uni.navigateTo({
					url: `/pages/myaccount/accountDetails?id=${id}`
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.account {
		.submit {
			background: #007AFF;
			color: #fff;
			text-align: center;
			border-radius: 40rpx;
			padding: 20rpx;
			width: 94%;
			box-sizing: border-box;
			// margin-top: 140rpx;
			position: fixed;
			bottom: 50rpx;
			left: 22rpx;
		}

		.image {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}

		image {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}

		.box {
			background-color: #fff;
			display: flex;
			align-items: center;
			padding: 17rpx;
			border-bottom: 1px solid #f1f1f1;

			.text {
				margin-left: 10rpx;
				font-size: 30rpx;

				.people {
					font-size: 26rpx;
					color: #666;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>